<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<link href="themes/css/ui.common.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.child.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
		<link href="style/jquery_ui/jquery-ui-1.8.custom.css" rel="stylesheet"
			type="text/css" />
		<link id="skin_css" rel="stylesheet" type="text/css"
			href="themes/css/ui.c.blue.css"></link>
		<link rel="stylesheet" href="themes/default/pagination.css"
			type="text/css"></link>
		<link rel="stylesheet" href="themes/css/ui.validation.css" type="text/css"></link>
		<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src="Scripts/jquery-ui-1.8.custom.min.js"
			type="text/javascript"></script>
		<script src="Scripts/ui.tips.js" type="text/javascript"></script>
		<script src="Scripts/ui.default.js " type="text/javascript"
			charset="UTF-8"></script>
		<script src="Scripts/ui.admincp.js" type="text/javascript"
			charset="UTF-8"></script>
		<script type="text/javascript" src="Scripts/jquery.json-2.2.min.js"></script>
		<STYLE type="text/css">
		.editorArea {
			display: none;
		}
		</STYLE>
		<script type="text/javascript" src="Scripts/ui.dialogFormHelper.js"></script>
		<script type="text/javascript" src="Scripts/ui.validation.js"></script>
		<script type="text/javascript">
			$(function(){
				switcher();
			 });
			
			var goodInfoIds  ="";
			
			function switcher() {
			    $("#dl_goodCategory").change(function () {
			        var categoryId = $(this).val();

			        $(".cb_goodInfo").attr("checked","");
			           
			        $.post("goodForCategory!queryGoodInfoByCategory.action", { "categoryId": categoryId }, function (data) {
			    
			           var jsonData = $.evalJSON(data);
			           
			           foreachHandler(jsonData,function(item){
			        	   
			        	   $("#cb_goodInfo_"+item).attr("checked","checked");
			        	   
			           });
			        });
			    });
			    
			    $("#btn_Submit").click(function(){
			    	getGoodIds();
			    	var categoryId = $("#dl_goodCategory").val();
			    	if(goodInfoIds  != ""){
			    		goodInfoIds = goodInfoIds.substring(0,goodInfoIds.length-1);
			    		$.post("goodForCategory!saveOrUpdate.action", { "categoryId": categoryId, "goodIds":goodInfoIds }, function (data) {
			    			if(data == 1){
			    				alert("保存成功");
			    			}else{
			    				alert("保存失败");
			    			}
			    		});
			    	}
			    });
			}
			
			function getGoodIds(){
				goodInfoIds  ="";
				var dataInControls = $(".cb_goodInfo:checked");

				dataInControls.each(function(item){
					goodInfoIds += $(dataInControls[item]).val() +","; 
				});
			}
			
		</script>
	</head>
	<body>
		<div class="PageChild_Title">
			<img src=" themes/images/default/icons/archives.png"
				class="PageChild_Tbtnpic" />
			<span class="PageChild_separate"></span>
			<span class="PageChild_TbtnText"><h2>
					物品与类型关联
				</h2>
			</span>
			<span class="PageChild_separate"></span>
			<div id="marker" class="red-tips">
			</div>
			<div class="clear">
			</div>
		</div>
		<div class="PageChild_Where">
			<table style="height: 60px;" border="0" cellpadding="0"
				cellspacing="0">
				<tr>
					<td class="mtd">
						物品类型：
					</td>
					<td class="mtd">
						<s:select list="goodCategoryList" listKey="categoryId" listValue="categoryName" headerKey="-1" headerValue="-请选择-" id="dl_goodCategory" name="categoryId" theme="simple" cssClass="selectable-field control-width-40 clearable" cssStyle="width: 200px; height: 26px"></s:select>
					</td>
				</tr>
			</table>
		</div>
		<div class="PageChild_List">
			<br/>
			<div>所有物品信息如下:</div>
			<br/>
			<div align="left" >
				${str}<br/><br/>
				<input type="button" id="btn_Submit" class="o-btn" value="保存">
			</div>
		</div>
</body>